package paulsnet;

import com.jme3.network.Network;
import com.jme3.network.Server;
import com.jme3.network.serializing.Serializer;
import com.simsilica.es.EntityData;
import com.simsilica.es.EntityId;
import com.simsilica.es.base.DefaultEntityData;
import com.simsilica.es.net.EntitySerializers;
import com.simsilica.es.server.EntityDataHostService;

/**
 *
 * @author eike
 */
public class ServerFast {

    public static void main(String[] args) {
        EntityData ed;
        EntityDataHostService edhs = null;
        EntityId eId;
        ed = new DefaultEntityData();
        eId = ed.createEntity();
        EntitySerializers.initialize();
        Serializer.registerClass(TestComponent.class);
        try {
            Server s = Network.createServer(1235);
            s.addChannel(1236);
            s.start();
            edhs = new EntityDataHostService(s, 0, ed);
            edhs.setAutoHost(true);
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
        long lastTime = 0;
        while (true) {

            long now = System.nanoTime();
            long trueTpf = now - lastTime;
            lastTime = now;
            System.out.println(trueTpf / 1E9);
            ed.setComponent(eId, new TestComponent());
            edhs.sendUpdates();
            try {
                Thread.sleep(1);
            } catch (Exception e) {
            }
        }
    }
}
